function PageBackendPackage(user, sd, options) {
  this._user = user;
  this._sd = sd;
  this._options = (options) ? options : null;
  
  this._gui = { name: document.getElementById('input1'),
                hours: document.getElementById('input2'),
                persons: document.getElementById('input3'),
                makeup: document.getElementById('input4'),
                type: document.getElementById('input5'),
                orderType: document.getElementById('input6'),
                price: document.getElementById('input7'),
                naviStatus: document.getElementById('td1'),
                purchases: document.getElementById('td2'),
                navigation: document.getElementById('img1'),
                btnBack: document.getElementById('img2'),
                sampleNew: document.getElementById('img3'),
                btnSave: document.getElementById('img4')
              };
  
  this._gui.makeup.options[this._gui.makeup.options.length] = new Option('');
  for (var i = 0, il = MakeupType.array().length; i < il; i++) {
    var type = MakeupType.array()[i];
    option = new Option(type);
    this._gui.makeup.options[this._gui.makeup.options.length] = option;
  }
  this._gui.type.options[this._gui.type.options.length] = new Option('');
  for (var i = 0, il = PackageType.array().length; i < il; i++) {
    var type = PackageType.array()[i];
    option = new Option(type);
    this._gui.type.options[this._gui.type.options.length] = option;
  }
  this._gui.orderType.options[this._gui.orderType.options.length] = new Option('');
  for (var i = 0, il = OrderType.array().length; i < il; i++) {
    var type = OrderType.array()[i];
    option = new Option(type);
    this._gui.orderType.options[this._gui.orderType.options.length] = option;
  }
  
  this._mode = false;
  
  this._createElements();
};

PageBackendPackage.prototype._createElements = function() {
  var a, tr, td, _self = this;
  
  this._gui.navigation.onclick = function() { location.href = '?p=pageasst&t=pagebackendpackages&m1=a4&m2=b3'; };
  DOMUtils.removeChildElements(this._gui.naviStatus);
  var img = document.createElement('img');
  if (this._options.pid) {
    img.src = 'images/pageasst/pagebackendpackage/editpackage.png';
  } else {
    img.src = 'images/pageasst/pagebackendpackage/addnewpackage.png';
  }
  this._gui.naviStatus.appendChild(img);
  
  this._loadData();
};

PageBackendPackage.prototype._loadData = function() {
  this._package = null;
  this._samples = null;
  this._retrievePackages();
  this._retrieveSamples();
};

PageBackendPackage.prototype._verifyData = function() {
  if (this._package && this._samples) {
    this._updateElements();
  }
};

PageBackendPackage.prototype._retrievePackages = function() {
  var _self = this;
  if (this._options.pid) {
    new RequestUtils()._read('package', null, 'd.oid = ' + this._options.pid, null, null, null, null, function(result, params) { _self._package = (result.data.length == 1) ? result.data[0] : null;
                                                                                                                                 _self._verifyData.call(_self);
                                                                                                                               }, null);
  } else {
    this._package = Package.instance();
    this._verifyData();
  }
};

PageBackendPackage.prototype._retrieveSamples = function() {
  var _self = this;
  new RequestUtils()._read('sample', null, null, null, null, null, null, function(result, params) { _self._samples = result.data;
                                                                                                    _self._verifyData.call(_self);
                                                                                                  }, null);
};

PageBackendPackage.prototype._updateElements = function() {
  var table, tr, td, _self = this;

  this._gui.name.value = this._package.name;
  this._gui.hours.value = this._package.hours;
  this._gui.persons.value = this._package.persons;
  for (var i = 0, il = this._gui.makeup.options.length; i < il; i++) {
    var option = this._gui.makeup.options[i];
    if (option.text == this._package.makeup) {
      this._gui.makeup.selectedIndex = i;
    }
  }
  for (var i = 0, il = this._gui.type.options.length; i < il; i++) {
    var option = this._gui.type.options[i];
    if (option.text == this._package.type) {
      this._gui.type.selectedIndex = i;
    }
  }
  for (var i = 0, il = this._gui.orderType.options.length; i < il; i++) {
    var option = this._gui.orderType.options[i];
    if (option.text == this._package.orderType) {
      this._gui.orderType.selectedIndex = i;
    }
  }
  this._gui.price.value = this._package.price;
  
  this._gui.name.onchange = function() { _self._package.name = this.value; };
  this._gui.hours.onchange = function() { _self._package.hours = this.value; };
  this._gui.persons.onchange = function() { _self._package.persons = this.value; };
  this._gui.makeup.onchange = function() { _self._package.makeup = this.options[this.selectedIndex].text; };
  this._gui.type.onchange = function() { _self._package.type = this.options[this.selectedIndex].text; };
  this._gui.orderType.onchange = function() { _self._package.orderType = this.options[this.selectedIndex].text; };
  this._gui.price.onchange = function() { _self._package.price = this.value; };
  this._gui.sampleNew.onclick = function() { var purchase = PackagePurchase.instance();
                                             purchase.product = Product.instance();
                                             purchase.product.sampleId = _self._samples[0].id;
                                             purchase.product.name = _self._samples[0].name;
                                             purchase.product.price = _self._samples[0].price;
                                             purchase.product.type = _self._samples[0].type;
                                             purchase.product.model = _self._samples[0].model;
                                             purchase.product.designId = MiscUtils.unique();
                                             purchase.product.selects = [];
                                             for (var i = 0, il = _self._samples[0].attributes.length; i < il; i++) {
                                               var attribute = _self._samples[0].attributes[i];
                                               var select = ProductSelect.instance();
                                               select.sampleAttributeOptionId = attribute.options[0].id;
                                               select.sampleAttributeId = attribute.id;
                                               select.sampleAttributeName = attribute.name;
                                               select.name = attribute.options[0].name;
                                               purchase.product.selects[purchase.product.selects.length] = select;
                                             }
                                             purchase.quantity = 1;
                                             purchase.price = purchase.product.price;
                                             _self._package.purchases[_self._package.purchases.length] = purchase;
                                             _self._updateElements.call(_self); 
                                           };
  
  DOMUtils.removeChildElements(this._gui.purchases);
  table = document.createElement('table');
  this._gui.purchases.appendChild(table);
 
  for (var i = 0, il = this._package.purchases.length; i < il; i++) {
    var purchase = this._package.purchases[i];
    
    tr = table.insertRow(-1);
    td = tr.insertCell(-1);
    new EditPurchase(td, purchase, function() { _self._updateElements.call(_self); }, { parent: this._package, samples: this._samples, prefix: new Date().getTime() + '_', index: i });
  }
  
  this._gui.btnSave.onclick = function() { new RequestUtils()._write('package', [_self._package], [], function() { location.href = '?p=pageasst&t=pagebackendpackages&m1=a4&m2=b3'; }, null); };
  this._gui.btnBack.onclick = function() { location.href = '?p=pageasst&t=pagebackendpackages&m1=a4&m2=b3'; };
};

